<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('我的机构')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>机构名称：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>机构类型：</label>
                                <div class="col-sm-2" >
                                    <select class="form-control"  name="infoType">
                                        <option value="">所有</option>
                                        <option value="API">api推送</option>
                                        <option value="CRM">crm后台</option>
                                    </select>
                                </div>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

<!--            <div class="btn-group-sm" id="toolbar" role="group">-->
<!--                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="special:info:apply">-->
<!--                    <i class="fa fa-plus"></i> 申请开户-->
<!--                </a>-->
<!--            </div>-->
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">

        var prefix = ctx + "special/info";

        $(function() {
            var options = {
                url: prefix + "/mineList",
                createUrl: prefix + "/apply",
                modalName: "机构信息",
                rowStyle: function(row, index) {   // 动态修改行的颜色
                    // 注意：即使不改变颜色，也得返回 '' ，否则会报错。
                    var result = '';
                    if (row.status == 1){
                        if (row.infoType == 'CRM'){
                            result = {css:{"background-color":"rgba(113,194,99,0.5)"}};
                        }else if (row.infoType == 'API'){
                            result = {css:{"background-color":"rgba(163,231,151,0.5)"}};
                        }
                    }
                    return result;
                },
                columns: [
                {
                    field: 'id',
                    title: '机构ID',
                },
                {
                    field: 'name',
                    title: '机构名称',
                    formatter: function (value, row, index){
                        var result = row.infoType;
                        if (row.infoType == 'CRM'){
                            result = '<span style="color: #1c84c6;" >'+row.infoType+'</a>';
                        }else if (row.infoType == 'API'){
                            result = '<span style="color: #c90e46;" >'+row.infoType+'</a>';
                        }
                        return row.name + '['+result+']';
                    }
                },
                {
                    field: 'descInfo',
                    title: '描述'
                },
                {
                    field: 'remainAmount',
                    title: '余额',
                    formatter: function (value, row, index){
                        var result = row.avaliableAmount;
                        if (result <= 200 && row.status == 1 ){
                            result = '<span style="color: #c90e46;" >'+result+'</a>';
                        }
                        return result
                    }
                },
                    {
                        field: 'adminAccount',
                        title: '账号信息',
                        formatter: function (value, row, index){
                            if (row.adminAccount == undefined || row.adminAccount == ''){
                                return '-';
                            }
                            return '<span style="color: darkgreen; border-bottom: 1px solid" onclick="showAccount(\''+row.name+'\' , \''+row.adminAccount+'\' , \''+ row.adminPwd +'\' )">展示</span>'
                        }
                    },
                    {
                        field: 'onlineInfo',
                        title: '在线信息'
                    },
                {
                    field: 'statusStr',
                    title: '状态',
                },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="itemInfoList(\'' + row.id+ '\', \''+ row.name + '\')"><i class="fa fa-list-ul"></i>任务</a> ');

                            if (row.infoType == 'CRM'){
                                actions.push('<a class="btn btn-primary btn-xs " href="javascript:void(0)" onclick="memberList(\'' + row.id+ '\', \''+ row.name + '\')"><i class="fa fa-list-ul"></i>成员</a> ');
                                actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="detailCrm(\'' + row.id+ '\' , \''+ row.name + '\')"><i class="fa fa-list-ul"></i>数据</a> ');
                            }else if (row.infoType == 'API'){
                                actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="detailApi(\'' + row.id+ '\' , \''+ row.name + '\')"><i class="fa fa-list-ul"></i>数据</a> ');
                            }
                            return actions.join('');
                        }
                    }
                ]
            };
            $.table.init(options);
        });

        function showAccount(name, account, pwd){
            var content =
                '账户：'+ name +
                '<br>账号：'+ account +
                '<br>密码：' + pwd +
                '<br>登陆地址：http://admin.renxinhua.cn'
            $.modal.alert(content, modal_status.MESSAGE, '账号信息');
        }

        /*字典列表-详细*/
        function detailCrm(infoId, name) {
            var url = ctx + 'special/data/'+infoId;
            $.modal.openTab(name + "-数据列表", url);
        }

        /*字典列表-详细*/
        function detailApi(infoId, name) {
            var url = ctx + 'special/apiData/item/'+infoId;
            $.modal.openTab(name + "-数据列表", url);
        }

        /*字典列表-详细*/
        function memberList(costomId, costomName) {
            var url = ctx + 'special/costomuser/'+costomId;
            $.modal.openTab(costomName + "—成员列表", url);
        }

        /***
         * 任务列表
         * @param costomId
         */
        function itemInfoList(costomId, costomName) {
            var url = ctx + 'special/itemInfo/'+costomId;
            $.modal.openTab(costomName + '-任务列表', url);
        }

    </script>
</body>
</html>